package com.zrar.ak.gkpt.controller.manage;


import com.zrar.ak.gkpt.model.vo.UserVO;
import com.zrar.ak.gkpt.service.manage.IManageCodeInfoService;
import com.zrar.ak.gkpt.service.user.IUserService;
import com.zrar.ak.gkpt.util.CommonTools;
import com.zrar.ak.gkpt.util.FormDataParameter;
import com.zrar.ak.gkpt.util.JsonResult;
import com.zrar.ak.gkpt.util.JsonResultEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @ClassName: ManageCodeInfoController
 * @Description 编码相关信息Controller层
 * @Author liyang
 * @Time 2020/03/09
 */
@RestController
@RequestMapping("/code")
@Api(tags = "编码相关信息接口")
@Slf4j   //该注解可以进行日志输出  log
public class ManageCodeInfoController {

    @Autowired
    private IUserService userService;
    @Autowired
    private IManageCodeInfoService manageCodeInfoService;

    @RequestMapping(value = "cudCodeInfo", method = RequestMethod.POST, produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "增改删编码信息", httpMethod = "POST", notes = "增改删编码信息")
    public JsonResult cudCodeInfo(HttpServletRequest request,
                                   @ApiParam(name = "formDataParameter", value = "增改删编码信息-编码操作数据参数") @RequestBody FormDataParameter formDataParameter){
        JsonResult jsonResult = new JsonResult();
        String formDataJson = formDataParameter.getFormDataJson();
        UserVO userVO = userService.getUserInformation(request);
        try {
            jsonResult = manageCodeInfoService.cudCodeInfo(jsonResult, formDataJson, userVO);
        } catch (Exception e) {
            e.printStackTrace();
            CommonTools.jsonResultSetParameter(jsonResult,JsonResultEnum.CODE_BUSINESS_EXCEPTION);
        }
        return jsonResult;
    }






}
